package com.ruoyi.merchant.controller;

import cn.hutool.core.lang.UUID;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.Page;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.PageDomain;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.core.web.page.TableSupport;
import com.ruoyi.merchant.annotation.DictFilter;
import com.ruoyi.merchant.domain.*;
import com.ruoyi.merchant.dto.ElectrocardiogramDataDto;
import com.ruoyi.merchant.service.IBluetoothService;
import com.ruoyi.merchant.vo.CustomerBaseVo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

import static com.ruoyi.common.core.utils.PageUtils.startPage;


@Slf4j
@RestController
@RequestMapping("/bluetooth")
public class BluetoothController extends BaseController {


    @Autowired
    private IBluetoothService bluetoothService;

    @PostMapping("/save")
    public AjaxResult saveData(@RequestBody Bluetooth bluetooth){
        String data = JSONObject.toJSONString(bluetooth);
        log.info("蓝牙数据：{}",data);
        bluetoothService.saveData(bluetooth);
        return AjaxResult.success();
    }


    /**
     *  查询心电数据
     * @Author chengxin.ju
     * @Date  2020/3/25
     * @Param [employeeDto]
     * @return ju.maiya.huo.system.entities.base.BaseResultEntity
     **/
    @ResponseBody
    @DictFilter(dataType = "page")
    @RequestMapping(value = "/listElectrocardiogram", method = RequestMethod.POST)
    public TableDataInfo listElectrocardiogram(@RequestBody ElectrocardiogramDataDto electrocardiogramDataDto) {
        TableDataInfo tableDataInfo = new TableDataInfo();
        if (StringUtils.isEmpty(electrocardiogramDataDto.getCustomerId())
                || StringUtils.isEmpty(electrocardiogramDataDto.getImei())){
            tableDataInfo.setSuccess(false);
            tableDataInfo.setMsg("客户id 不能为空 ！");
            tableDataInfo.setMsg("设备设备码 不能为空 ！");
            return tableDataInfo;
        }
        if (electrocardiogramDataDto.getPageNum() == null){
            electrocardiogramDataDto.setPageNum(1);
        }
        if (electrocardiogramDataDto.getPageSize() == null){
            electrocardiogramDataDto.setPageSize(10);
        }
        Page<ElectrocardiogramData> electrocardiogramData = bluetoothService.listElectrocardiogram(electrocardiogramDataDto);
        return getDataTable(electrocardiogramData);
    }

    /**
     *  查询心电数据
     **/
    @ResponseBody
    @RequestMapping(value = "/selectElectrocardiogramById", method = RequestMethod.GET)
    public AjaxResult selectElectrocardiogramById(@RequestParam String id) {
        ElectrocardiogramItem electrocardiogramItem = bluetoothService.selectElectrocardiogramById(id);
        return AjaxResult.success(electrocardiogramItem);
    }


}
